package com.example.food_contract_system.controller;

import com.example.food_contract_system.service.BossService;
import com.example.food_contract_system.service.FoodService;
import com.example.food_contract_system.util.R;
import com.example.food_contract_system.vo.AddFoodVo;
import com.example.food_contract_system.vo.BossUpdateVo;
import com.example.food_contract_system.vo.FoodByImgListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author LiHaoyang
 * @date 2023/7/6  9:25
 **/
@RestController
@RequestMapping("/boss")
public class BossController {

    @Autowired
    private BossService bossService;
    @Autowired
    private FoodService foodService;

    /**
     * 厂商管理页中 展示经销商的列表
     * 组装成树形结构
     * @return
     */
    @GetMapping("/getManagerAgencyList")
    public R getManagerAgencyList(){
        R result = bossService.getManagerAgencyList();
        return result;
    }

    /**
     * 审核，更新经销商的审核状态
     * @param opt
     * @return
     */
    @GetMapping("/updateStatus/{opt}/{id}")
    public R updateStatus(@PathVariable("opt") String opt,
                          @PathVariable("id") String id){
        R result = bossService.updateStatus(opt,id);
        return result;
    }

    /**
     * 删除，厂商删除经销商
     * @return
     */
    @GetMapping("/deleteAgency")
    public R deleteAgency(@RequestParam("pwd") String password,
                          @RequestParam("id") String id,
                          @RequestParam("bid") String bid){
        R result = bossService.deleteAgency(password,id,bid);
        return result;
    }

    /**
     * 审核总览，列表获取
     * @return
     */
    @GetMapping("/getStatusList/{status}")
    public R getStatusList(@PathVariable("status") String status){
        R result = bossService.getStatusList(status);
        return result;
    }

    /**
     * 审核总览，列表筛选
     * @return
     */
    @PostMapping("/batchApproval/{opt}")
    public R BatchApproval(@RequestBody String list,
                           @PathVariable("opt") String opt){
        R result = bossService.batchApproval(list,opt);
        return result;
    }

    /**
     * 产品，添加
     * @param addFoodVo
     * @return
     */
    @PostMapping("/addFood")
    public R AddFood(@RequestBody AddFoodVo addFoodVo){
        R result = bossService.addFood(addFoodVo);
        return result;
    }

    /**
     * 产品，获取列表
     * @return
     */
    @GetMapping("/getFoodList")
    public R getFoodList(){
        R result = foodService.getFoodAll();
        return result;
    }

    /**
     * 产品，获取列表 携带照片列表
     * @return
     */
    @GetMapping("/getFoodListByImgList/{id}")
    public R getFoodListByImgList(@PathVariable("id") Integer id){
        R result = foodService.getFoodListByImgList(id);
        return result;
    }

    /**
     * 产品，更新产品信息
     * @return
     */
    @PostMapping("/updateFoodMsg")
    public R updateFoodMsg(@RequestBody FoodByImgListVo foodByImgListVo){
        R result = bossService.updateFoodMsg(foodByImgListVo);
        return result;
    }

    /**
     * 产品，删除产品
     * @param id
     * @return
     */
    @GetMapping("/deleteProduct/{id}")
    public R deleteProduct(@PathVariable("id") Integer id){
        R result = foodService.deleteProduct(id);
        return result;
    }

    /**
     * 展示经销商的订单列表
     * 组装成树形结构
     * @return
     */
    @GetMapping("/getOrderAgencyList")
    public R getOrderAgencyList(){
        R result = bossService.getOrderAgencyList();
        return result;
    }

    @GetMapping("/getBoss/{bId}")
    public R getBoss(@PathVariable("bId") String bId){
        return bossService.getBoss(bId);
    }

    @PostMapping("/updatePwd/{bid}")
    public R updatePwd(@RequestBody BossUpdateVo bossUpdateVo,
                       @PathVariable("bid") String bid){
        return bossService.updatePwd(bossUpdateVo,bid);
    }

    @PostMapping("/updatePwd2/{bid}")
    public R updatePwd2(@RequestBody BossUpdateVo bossUpdateVo,
                       @PathVariable("bid") String bid){
        return bossService.updatePwd2(bossUpdateVo,bid);
    }
}
